package com.linlong.linlongchat.controller;


import com.linlong.linlongchat.domain.po.Result;
import com.linlong.linlongchat.domain.vo.ApplyVo;
import com.linlong.linlongchat.service.IApplyService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 申请表 前端控制器
 * </p>
 *
 * @author 华少
 * @since 2024-09-19
 */
@RestController
@RequestMapping("/apply")
@Api(tags = "申请接口")
public class ApplyController {
    @Autowired
    private IApplyService applyService;

    @PostMapping("/add/{responseAccount}")
    @ApiOperation("添加申请")
    public Result addApply(@PathVariable String responseAccount) {
        boolean flag = applyService.addApply(responseAccount);
        if (flag) {
            return Result.ok("申请成功");
        }else {
            return Result.fail("申请还未处理");
        }
    }

    @PutMapping("/status/{id}/{status}")
    @ApiOperation("修改申请状态")
    public Result updateApplyStatus(@PathVariable Long id, @PathVariable Integer status) {
        if (applyService.updateApplyStatus(id, status)){
            return Result.ok("修改成功");
        }else{
            return Result.ok("修改失败");
        }
    }

    @GetMapping("/list")
    @ApiOperation("查询申请者列表")
    public Result<List<ApplyVo>> getAllApplies() {
        return Result.ok(applyService.getAllApplies());
    }


    @GetMapping("/status")
    @ApiOperation("查询未处理消息数量")
    public Result<Long> CountAllNotCheckedStatus() {
        return Result.ok(applyService.CountAllNotCheckedStatus());
    }

}
